//
//  String+ExtensionTests.swift
//  TDDStudySwift
//
//  Created by baidu on 6/28/16.
//  Copyright © 2016 caoyuan. All rights reserved.
//

import XCTest

class String_ExtensionTest_Range: XCTestCase {
    
    func testRange() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a[0..<2]
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, "12", "😡result should be 12😡")
    }
    
    func testFind() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a["324"]
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, -1, "😡result should be -1😡")
    }
    func testFind2() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a[""]
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, -1, "😡result should be -1😡")
    }
    func testFind3() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a["6"]
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, 5, "😡result should be 5😡")
    }
    func testFind4() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a["7"]
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, -1, "😡result should be -1😡")
        
    }
    

}

class String_ExtensionTest_replace: XCTestCase {
    
    func testReplace() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a.pyReplace(str: "23", withStr:"xxxx")
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, "1xxxx456", "😡result should be 1xxx456😡")
    }
    
    func testReplace1() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a.pyReplace(str: "", withStr:"xxxx")
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, "123456", "😡result should be 123456😡")
    }

    func testReplace2() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a.pyReplace(str: "23", withStr:"")
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, "1456", "😡result should be 1456😡")
    }
}

class String_ExtensionTest_reverse: XCTestCase {
    
    func testReverse() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        let a = "123456"
        let result = a.pyReverse()
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, "654321", "😡result should be 654321😡")
    }
    
    
}

class String_ExtensionTest_split: XCTestCase {
    
    func testPySplit() {
        let a = "1,2,3,"
        let result = a.pySplit(str: ",")
        print("😄👉\(result)👈😄")
        XCTAssertEqual(result, ["1", "2", "3"], "😡result should be 1234567😡")
    }
}

